package com.wuyou.mid;

public class NextGreaterElements {


    public static void main(String[] args) {
        int[] nums = {1,2,1};
        NextGreaterElements nextGreaterElements = new NextGreaterElements();
        System.out.println(nextGreaterElements.solution_1(nums));
    }


    public int[] solution_1(int[] nums){
        int length = nums.length;
        int[] ans = new int[length];
        int ans_idx=0;
        while(ans_idx<length){
            int nums_idx=ans_idx+1, temp_idx = nums_idx%length;
            while(temp_idx!=ans_idx && nums[temp_idx]<=nums[ans_idx]){
                nums_idx++;
                temp_idx = nums_idx%length;
            }
            if(temp_idx==ans_idx){
                ans[ans_idx]=-1;
            }else{
                ans[ans_idx]=nums[temp_idx];
            }
            ans_idx++;
        }
        return ans;
    }
}
